#coding=utf-8
import unittest
import os
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import pyautogui as pag
import time
import  random
import urllib

class userfulToolsFactory():
    def test_check(self,type,str):
        ReportSuccessful = "您上报的问题已经成功提交到监督中心"
        if ReportSuccessful.decode("utf-8")in str:
            return True
        else:
            return False

    def creat_dir(self,base_dir):
        timestr = time.strftime('%Y-%m-%d', time.localtime(time.time()))  # 本地日期时间作为测试报告的名字
        randomStr = str(random.uniform(5,500))
        relative_address = timestr + '-' + randomStr
        os.makedirs(base_dir + relative_address)

        return relative_address

    def update_file_path_deal(self,file_path):
        update_file_path = file_path.replace("/","\\")
        # print update_file_path
        return update_file_path

    def file_path_deal(self,file_path):
        base_path = file_path.replace("\\", "/")
        # print update_file_path
        return base_path

    def CaseNameOp(self,casetitle):
        startStr = 'u"'
        endStr = ')"'
        CaseName = casetitle[startStr:endStr]
        print CaseName

    # 根据传入的数据进行 字符串的处理
    def SubString_handle(self,str_source,startStr,endStr):
        startNum = str(str_source).find(startStr)
        endNum = str(str_source).find(endStr)
        str_result = str(str_source)[startNum+len(startStr):endNum]
        print str_result
        return str_result

    #处理从数据库中查询到的数据，去掉(,)字符，并返回
    def db_data_deal(self,db_data):
        startnum = str(db_data).find('(')
        endnum = str(db_data).find(',)')
        format_date = str(db_data)[startnum+1:endnum]
        return format_date

    #根据传入的参数进行比对，检查是否该案件在 某个 授权阶段
    def accredit_status_check(self,item_menu_set,accredit_tpye):
        if accredit_tpye in str(item_menu_set):
            return True
        else:
            return False
    #根据鼠标的位置，获取当前屏蔽的当前位置的坐标
    def get_current_position(self):
        try:
            while True:
                print "Press Ctrl-C to end"
                x, y = pag.position()
                posStr = "Position:" + str(x).rjust(4) + ',' + str(y).rjust(4)
                print posStr
                time.sleep(0.2)
                os.system('cls')
                print u'当前坐标为：' + str(x) + ' , ' + str(y)
        except  KeyboardInterrupt:
            print 'end....'

    #检查url是否可以正常访问
    def url_get_check(self,url):
        # url = 'http://123.57.173.230:8081/MediaRoot/rec/20170927/1057/415da01a-359b-49ec-a13a-f8523ddfead5/1057123.png?1506492179156'
        resp = urllib.urlopen(url)
        code = resp.getcode()
        print('the result is :', code)
        if code == 200:
            return True
        else:
            return False
if __name__ == '__main__':
    test = userfulToolsFactory()
    # userfulToolsFactory.creat_dir(test,'D://Cruise//pythonSrc//reprot//')
    # case = 'u"StartTest(/''login_egova/'')"'
    # test.CaseNameOp(case)
    # test.update_file_path_deal('D:/SVN/V15/zx2016/Client/Python/eUrbanMIS/updatefile/9.jpg')
    # test.Oracel_data_deal('(1234,)')
    # test.get_current_position()
    str_source = '案件登记 （任务号：201709120001）'
    start = '：'
    end = '）'
    test.SubString_handle(str_source,start,end)
    unittest.main()


